/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import CRUD.MemberHome;
import beans.RegisterBeanForum;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import xmlMapping.Member;

/**
 *
 * @author labib
 */
public class editAccount extends org.apache.struts.action.Action {
    
    /* forward name="success" path="" */
    private static final String SUCCESS = "editAccount";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        if(request.getSession().getAttribute("id").equals(null))
        {
             return mapping.findForward("login");
        }
                  System.out.println(" finished getting member and set  it in form bean");
       Member m=new MemberHome().findById((Integer)request.getSession().getAttribute("id"));
       System.out.println("username xxxxx"+m.getUserName());
       System.out.println("username xxxxx"+m.getEmail());
      RegisterBeanForum formbean=new RegisterBeanForum();
      formbean.setUserName(m.getUserName());
      formbean.setPassword("");
      formbean.setEmail(m.getEmail());
      formbean.setLastName(m.getLname());
      formbean.setFirstName(m.getFname());
      formbean.setStreet(m.getStreet());
      formbean.setCity(m.getCity());
      formbean.setCountry(m.getCountry());
     formbean.setImageName(m.getPhoto());
     formbean.setBirthday(m.getBirthday().toString());
      request.setAttribute("reg", formbean);
        return mapping.findForward("edit");
    }
}
